package com.yupi.usercenter.exception;

import com.yupi.usercenter.commons.ErrorCode;

/**
 * @author 麦翔盛
 * @ClassName: BussinessException
 * @Package: com.yupi.exception
 * @description: 自定义异常
 * @date 2022/4/13 15:40
 */
public class BusinessException extends RuntimeException{
    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 错误描述
     */
    private final String description;


    public BusinessException(String message, Integer code, String description) {
        super(message);
        this.code = code;
        this.description = description;
    }

    /**
     * 通过错误码获取错误信息
     * @param errorCode 错误码
     */
    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = errorCode.getDescription();
    }

    /**
     * 通过错误码获取错误信息和错误码 自己传入错误描述
     * @param errorCode 错误码
     * @param description 错误具体描述
     */
    public BusinessException(ErrorCode errorCode,String description) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
}
